package com.dp.appi.controller;

import com.dp.appi.service.ModuleService;
import com.dp.appi.util.ExceptionUtil;
import com.dp.appi.util.SYS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * Created by xiaoji on 2016/5/13.
 * 模块材料
 */
@Controller
@RequestMapping(value = "/moduleControl")
public class ModuleControl {
    private static Logger log = LoggerFactory.getLogger(ModuleControl.class);
    @Autowired
    private ModuleService moduleService;

    /**
     * 获取模块列表
     * @param modelMap
     * @param param 查询参数
     * @param s 开始序列
     * @param n 获取条数
     */
    @RequestMapping(value = "/moduleList",method = RequestMethod.GET)
    public void moduleList(ModelMap modelMap,@RequestParam Map<String,String> param,Integer s,Integer n) {
        try {
            String versionid ="0";
            if(param.containsKey("versionid"))
            {
                versionid=param.get("versionid");
            }
            modelMap.addAttribute("moduleList",moduleService.moduleList(param.get("name"),versionid, s, n));
        }catch (Exception e){
            modelMap.addAllAttributes(SYS.E10002.msgMap());
            log.error(ExceptionUtil.getExceptionAllinformation(e));
        }
    }
}
